<template>
  <div>
    <!-- 搭建基本布局 el-container -->
    <el-container>
      <el-header>小U商城大型后台管理系统
        <div>
          用户名：<span>{{username}}</span>
          <el-button @click='logout' type='danger' size='small' class="btn">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="220px">
          <v-nav></v-nav>
        </el-aside>
        <el-main>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//引入左侧导航菜单
import vNav from "../components/vNav.vue";
export default {
  data() {
    return {
          username:''
    }
  },
  mounted() {
    this.username = JSON.parse(sessionStorage.getItem('userinfo')).username
  },
  methods: {
    //封装一个退出事件
    logout(){
      // 退出的逻辑两个步骤
      //一、清空你的存储内容(在这是重新触发行动)
      this.$store.dispatch('changeUser',false)
      //二、跳转到登录页
      this.$router.push('/login')
    }
  },
  components: {
    vNav,
  },
};
</script>

<style scoped>
.el-header {
  background: rgb(97, 39, 231);
  text-align: center;
  color: #fff;
 font-size: 20px;
}
.btn{
 margin-left: 800px;
}
.el-header div span{
color: rgb(238, 197, 15);
}

</style>
